<?php use_helper('Date');?>

<h1><?php echo __('Process detail')?></h1>
  	<fieldset><legend><?php echo __('Available actions')?></legend>
  	<div id="actions" style="float:left">
		<?php 
		$pers = $sf_user->getUserProfile();
		$arrayActions = $demande->getNextStates($sf_user->getAttribute('nni'),false,'','',$pers) ;
		$actions = $demande->getNextStatesHtml($arrayActions, '32','','',$pers) ;
      	echo $actions; 
      	if($demande->brouillon){
      	  			echo link_to('<img title="'.__('Confirm').'&nbsp;'.$demande->typedossier->typedossier->description.'" src="/images/iconsEtats/32/confirm.png"></img>', 'demandes/confirmer?id='.$demande->id);
      	}      	?>
    </div>  
    <div class="buttons" style="float:right">
	<?php 
		$moduleView = $sf_user->getAttribute('viewOriginal');
		$modulePage = $sf_user->getAttribute('viewPage');
		if($moduleView=='') $moduleView = 'index';
	?>    
	<?php
		echo link_to('<img title="'.__('Go back').'" src="/images/formulaires/retour.png">',$sf_user->getAttribute('myRoute'));
	?>

	<?php
		if(!$demande->ferme and !$demande->fermeTechnique and sfConfig::get('app_fonctions_recycle',false)){
			if(count($arrayActions)>0 or $demande->brouillon){
				echo link_to('<img title="'.__('Close process and recreate it as a new one').'" src="/images/formulaires/recycle.png">','dossiers/recycle?id_demande=' . $demande->id);
			}
		}
		
    	echo link_to('<img title="'.__('Post a message').'" src="/images/formulaires/chat.png">','message/new?id=' . $demande->id . '&classname=dossier');
    	echo link_to('<img title="'.__('Create an evenement').'" src="/images/formulaires/event.png">','evenement/new?id=' . $demande->id . '&classname=dossier');
    	echo link_to('<img title="'.__('Save as pdf').'" src="/images/icons/48/pdf.png"/>', 'dossiers/printPdf?id='.$demande->id.'&className='. get_class($demande));
    	echo link_to('<img title="'.__('Download all files').'" src="/images/icons/48/zip.png"/>', 'dossiers/zipFiles?id='.$demande->id.'&className='. get_class($demande));
    	
    ?>
    <!-- 
	  <a href="#" onclick="printDiv();return false;"><img src="/images/formulaires/print.png" title="<?php echo __('Print')?>"></a>
	 -->
	   <?php 
	  $q = Doctrine_Query::create()
    			->select('*')
    			->from('downloadconfig d')
    			->where('d.categorie_id = ' . $demande->categorie->id)
      			->setHydrationMode(Doctrine_Core::HYDRATE_ARRAY);
      $items = $q->execute();
	  ?>
	  <?php foreach($items as $configDownload):?>
	  		<?php 
	  			switch ($configDownload['type']){
				    case 'word':
				        $icon ='downloadWord.png';
				        break;
				    case 'excel':
				        $icon ='downloadExcel.png';
				        break;
				    case 'pdf':
				        $icon ='downloadPdf.png';
				        break;
				    default:
				    	$icon ='downloadOther.png';
				}

	  		
	  		?>
	  		<?php echo link_to('<img title="'.__('Download').'" src="/images/icons/48/'.$icon.'">','mesdossiers/download?id_demande=' . $demande->id . '&id_config=' . $configDownload['id']);?>
	  <?php endforeach;?>
	</div>
  	</fieldset>
<div id="DivIdToPrint">

<?php $history = $demande->getStatesList2(); ?>

<?php if(count($history) > 0):?>
  	<fieldset><legend><?php echo __('Process history')?></legend>
	  	<table>
	  	<tbody>
		  <?php foreach($history as $etat):?>
			<tr>
		      <th width = "16%" style="text-align: center;"><?php echo format_date($etat->created_at) ?></th>
		      <td style="text-align: center;"><?php echo $etat->personne->name; ?></td>
		      <td width = "16%" style="text-align: center;"><?php echo $etat->etat->description; ?>
		      </td>
		      <td width = "50%" style="text-align: center;"><?php 
				if($etat->prestataire)
				{
		      	 	echo __('Process asigned to a service provider:').'&nbsp;'.$etat->nom_prestataire."<br/>";
		      	}
		      	echo $etat->commentaire;
		      	?></td>
		    </tr>
		  <?php endforeach;?>
		</tbody>
	  	</table>
  	</fieldset>
<?php endif;?>

<?php include_partial('dossiers/showDemande', array('demande'=>$demande)) ?>
</div>